package com.ethereal.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@WebServlet("/session")
public class Session1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Map<String, String[]> map = req.getParameterMap();
        String userName = req.getParameter("userName");
        String passWord = req.getParameter("passWord");

        if (userName.equals("chu") && passWord.equals("1234")){
            User user = new User();
            user.setUserName(userName);
            user.setPassWord(passWord);

            req.getSession().setAttribute("User", user);
            resp.sendRedirect(req.getContextPath() + "/hello");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
